@extends('admin.layout.global')

@section('css-plugins')
    <link href="{{ asset('style/plugins/chosen_v1.2.0/chosen.min.css') }}" rel="stylesheet">
    <link href="{{ asset('style/plugins/daterangepicker/daterangepicker.css') }}" rel="stylesheet">
@endsection

@section('css')
    <link href="{{ asset('style/admin/css/custom.css') }}" rel="stylesheet">
    <style>
        .pagination {
            margin: 0 0;
        }
        .form-group {
            margin-bottom: 0;
        }
    </style>
@endsection

@section('js-plugins')
    <script src="{{ asset('style/plugins/chosen_v1.2.0/chosen.jquery.min.js') }}"></script>
    <script src="{{ asset('style/plugins/moment/moment.js') }}"></script>
    <script src="{{ asset('style/plugins/daterangepicker/daterangepicker.js') }}"></script>
@endsection

@section('js')
    <script src="{{ asset('style/admin/js/pages/blankon.form.element.js') }}"></script>
    <script>
        $(function(){
            var menu = $(".dropdown-menu").find("a");
            menu.click(function(){
                var text = $(this).text();
                var k = $(this).data('key');
                $('#showKey').text(text);
                $('#searchType').val(k);
            });
        });
    </script>
    <script>
        $(document).ready(function () {
            //定义
            var $goodsClassify        = $("select[name='goodsClassify']");
            //查询
            function getQuery() {
                var goodsClassify         = $goodsClassify.val();
                var separator       = '?';
                var url = '{{ action('Admin\Shop\GoodsController@getIndex') }}';
                if (goodsClassify != '')
                {
                    url += separator + 'goodsClassify=' + goodsClassify;
                    separator = '&';
                }
                window.location = url;
            }
            $('#dateTime').daterangepicker({
                "autoUpdateInput": false,
                "timePicker": true,
                "timePicker24Hour": true,
                "timePickerSeconds": true,
                "timePickerIncrement": 1,
                "locale": {
                    "format": "YYYY-MM-DD HH:mm:ss",
                    "separator": " - ",
                    "applyLabel": "提交",
                    "cancelLabel": "取消",
                    "fromLabel": "From",
                    "toLabel": "To",
                    "customRangeLabel": "Custom",
                    "daysOfWeek": [
                        "日",
                        "一",
                        "二",
                        "三",
                        "四",
                        "五",
                        "六"
                    ],
                    "monthNames": [
                        "一月",
                        "二月",
                        "三月",
                        "四月",
                        "五月",
                        "六月",
                        "七月",
                        "八月",
                        "九月",
                        "十月",
                        "十一月",
                        "十二月"
                    ],
                    "firstDay": 1,
                },
                "drops": "down"
            }, function(start, end, label) {
            });
            $('#dateTime').on('apply.daterangepicker', function(ev, picker) {
                $(this).val(picker.startDate.format('YYYY-MM-DD HH:mm:ss') + " - " + picker.endDate.format('YYYY-MM-DD HH:mm:ss'));
                getQuery();
            });
            @if(isset($_GET['time']) && $_GET['time'] != '')
            @else
            $('#dateTime').val('');
            @endif
            $('.inputSelect').change(function(){
                getQuery();
            });
        });
    </script>
@endsection


@section('content')
    <div class="body-content animated fadeIn">
        <div class="row">
            <div class="col-md-12">
                <!-- Start inline form -->
                <div class="panel rounded shadow">
                    <div class="panel-body no-padding">
                        <div class="form-horizontal mt-10">
                            <div class="form-body">
                                <div class="form-group">
                                    <div class="col-sm-2">
                                        <select data-placeholder="选择分类" name="goodsClassify" class="chosen-select mb-15 inputSelect" tabindex="2">
                                            <option value="">全部分类</option>
                                            @foreach($goodsClassify as $v)
                                                <option value="{{ $v->id }}" @if(isset($_GET['goodsClassify']) && $_GET['goodsClassify'] == $v->id) selected @endif>{{ $v->name }}</option>
                                            @endforeach
                                        </select>
                                    </div>
                                    <div class="col-sm-3">
                                    </div>
                                    <div class="col-sm-3"></div>
                                    <div class="col-sm-4">
                                    </div>
                                </div><!-- /.form-group -->
                            </div><!-- /.form-body -->
                        </div>

                    </div><!-- /.panel-body -->
                </div><!-- /.panel -->
                <!--/ End inline form -->
                <!-- Start basic color table -->
                <div class="panel">
                    <div class="panel-heading">
                        <div class="pull-left">
                            <a href="{{ action('Admin\Shop\GoodsController@getAdd') }}" class="btn btn-success btn-sm"><i class="fa fa-plus"></i> {{ getLang('Tips', 'create') }}</a>
                        </div>
                        <div class="clearfix"></div>
                    </div><!-- /.panel-heading -->
                    <div class="panel-body no-padding">
                        <div class="table-responsive" style="margin-top: -1px;">
                            <table class="table table-striped table-success">
                                <thead>
                                <tr>
                                    <th class="text-center border-right" style="width: 5%">ID</th>
                                    <th>商品名</th>
                                    <th>分类</th>
                                    <th>单价</th>
                                    <th class="text-center" style="width: 12%;">{{ getLang('Tips', 'operation') }}</th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach($goods as $v)
                                    <tr>
                                        <td class="text-center border-right">{{ $v->id }}</td>
                                        <td>
                                            <img src="{{ action('ImgController@getPicture', ['sourceName' => $v->thumb, 'size' => '20x20']) }}" width="22">
                                            <span>{{ $v->title }}</span>
                                        </td>
                                        <td>{{ isset($goodsClassify[$v->classifyID]) ? $goodsClassify[$v->classifyID]->name : '未知' }}</td>
                                        <td>{{ $v->price }}</td>
                                        <td class="text-center">
                                            <a href="{{ action('Admin\Shop\GoodsController@getEdit', ['id' => $v->id]) }}" class="btn btn-primary btn-xs" data-toggle="tooltip" data-placement="top" data-original-title="{{ getLang('Tips', 'edit') }}"><i class="fa fa-pencil"></i></a>
                                            <button data-url="{{ action('Admin\Shop\GoodsController@getDel', ['id' => $v->id]) }}" data-tips='{{ getLang('Tips', 'isDelete') }} : {{ $v->title }}' class='btn btn-danger btn-xs delete-table' data-toggle="tooltip" data-placement="top" data-original-title="{{ getLang('Tips', 'delete') }}"><i class="fa fa-times"></i></button>
                                        </td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                        </div><!-- /.table-responsive -->
                    </div><!-- /.panel-body -->
                    <div class="panel-footer">
                        <div class="row">
                            <div class="col-md-12">
                                <div style="text-align: center">
                                    <?php
                                        if(isset($_GET['goodsClassify']))
                                            $goods->appends(['goodsClassify' => $_GET['goodsClassify']]);
                                    ?>
                                    {!! $goods->render() !!}
                                </div>
                            </div>
                        </div>
                    </div>
                </div><!-- /.panel -->
                <!--/ End basic color table -->

            </div><!-- /.col-md-12 -->
        </div>
    </div>
@endsection